#include "comm.h"
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
  //创建key
	key_t k = ftok(PATH_NAME, PORJ_ID);
	if(k < 0)
  {
    perror("ftok");
    return 1;
  }
  printf("key: %x\n", k);
  
  //申请共享内存
  int shmid = shmget(k, SIZE, IPC_CREAT);
  if(shmid < 0)
  {
    perror("shmget");
    return 2;
  }
  printf("shmid: %d\n", shmid);

  //挂载共享内存
  char *start = (char*)shmat(shmid, NULL, 0);
  
  while(1)
  {
    printf("%s\n", start);
    sleep(1);
  }

  //去关联
  shmdt(start);

	return 0;
}
